c531ae1
@@ -342,6 +342,15 @@
static void configureDebugVariablesForChildJVM(Map<String, String> environmentVa
         + " environment variable must be set to \"y\" or \"n\" when debugging";
 
     if (environmentVariables.get(HIVE_DEBUG_RECURSIVE).equals("y")) {
+      // HADOOP_CLIENT_OPTS is appended to HADOOP_OPTS in HADOOP.sh, so we should remove the old
+      // HADOOP_CLIENT_OPTS which might have the main debug options from current HADOOP_OPTS. A new
+      // HADOOP_CLIENT_OPTS is created with child JVM debug options, and it will be appended to
+      // HADOOP_OPTS agina when HADOOP.sh is executed for the child process.
+      assert environmentVariables.containsKey(HADOOP_OPTS_KEY)
+        && environmentVariables.get(HADOOP_OPTS_KEY) != null: HADOOP_OPTS_KEY
+        + " environment variable must have been set.";
+      environmentVariables.put(HADOOP_OPTS_KEY, environmentVariables.get(HADOOP_OPTS_KEY)
+        .replace(environmentVariables.get(HADOOP_CLIENT_OPTS), ""));
       // swap debug options in HADOOP_CLIENT_OPTS to those that the child JVM should have
       assert environmentVariables.containsKey(HIVE_CHILD_CLIENT_DEBUG_OPTS)
           && environmentVariables.get(HIVE_CHILD_CLIENT_DEBUG_OPTS) != null : HIVE_CHILD_CLIENT_DEBUG_OPTS
